package com.lzs.kunei.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzs.entity.Inventory;
import com.lzs.entity.Locator;
import com.lzs.entity.Move;
import com.lzs.kunei.service.InventoryService;
import com.lzs.util.R;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wpy
 * @since 2020-11-24
 */
@ApiModel(value = "盘点订单")
@RestController
@RequestMapping("/kunei/inventory")
public class InventoryController {
    @Autowired
    private InventoryService inventoryService;
    @ApiOperation(value = "添加盘点单")
    @PostMapping("/addInventory")
    public R addInventory(@RequestBody Inventory inventory){
        try {
            inventoryService.save(inventory);
            return R.ok().message("添加盘点单成功");
        }catch (RuntimeException e){
            return R.error().message("添加盘点单失败");
        }

    }
    /*
    @ApiOperation(value = "查询盘点单")
    @PostMapping("/selectInventoryPage/{current}/{size}")
    public R selectPutonPage(@PathVariable Integer current, @PathVariable Integer size, @RequestBody Inventory inventory){
        String inventoryno = inventory.getInventoryno();
        Page<Inventory> inventoryPage=new Page<>(current,size);
        QueryWrapper<Inventory> queryWrapper=new QueryWrapper<>();
        if (StringUtils.isNotEmpty(inventoryno)){
            queryWrapper.like("inventoryno",inventory);
        }
        try {
            inventoryService.page(inventoryPage,queryWrapper);
            return R.ok().message("查询成功").data("inventoryPage",inventoryPage);
        }catch (RuntimeException e){
            e.printStackTrace();
            return R.error().message("查询出错");
        }
    }

     */

    @ApiOperation(value = "查询盘点单")
    @PostMapping("/selectInventoryPage/{current}/{size}")
    public R selectPutonPage2(@PathVariable Integer current, @PathVariable Integer size, @RequestBody Locator search){
        System.out.println(search.toString());
        String name = search.getName();
        String inventoryno = search.getCode();
        List<Long> wids = search.getWids();
        Map map1=new HashMap();
        map1.put("name",name);
        map1.put("inventoryno",inventoryno);
        map1.put("current",current);
        map1.put("size",size);
        IPage<Locator> inventoryIPage = inventoryService.selectInventoryPage(map1,wids);
        return R.ok().data("page",inventoryIPage);
    }


}

